﻿IF OBJECT_ID('up_Utility_Asset_XMissionStructures_Poles_ValidateIds') IS not NULL
	DROP PROC up_Utility_Asset_XMissionStructures_Poles_ValidateIds

GO

CREATE PROCEDURE [dbo].[up_Utility_Asset_XMissionStructures_Poles_ValidateIds]
(
	@utilityId int,
	@assetIdList varchar(max)
)
AS

SELECT 
	CAST(Value AS int) as AssetId
FROM
	(select 
		Value 
	 from 
		dbo.fn_Split(@assetIdList, default)
	) as List
WHERE
	Value NOT IN (
		SELECT 
			Utility_Asset_XMissionStructures_PoleId 
		FROM
			tb_Utility_Asset_XMissionStructures_Poles assetPoles
		INNER JOIN tb_Utility_Asset_XMissionStructures assetSt
			ON assetSt.Utility_Asset_XMissionStructureId = assetPoles.Utility_Asset_XMissionStructureFK
		WHERE 
			assetSt.UtilityFk = @utilityId
	)

 